/*
 * @copyright (c) 2023, MacRsh
 *
 * @license SPDX-License-Identifier: Apache-2.0
 *
 * @date 2023-11-17    MacRsh       First version
 */

#ifndef _ETASK_H_
#define _ETASK_H_

#include "etask_config.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifdef MR_USING_ETASK

/**
 * @brief Error code.
 */
#define MR_EOK                          (0)                         /**< No error */
#define MR_ENOMEM                       (-1)                        /**< No enough memory */
#define MR_ENOTFOUND                    (-3)                        /**< Not found */
#define MR_EBUSY                        (-4)                        /**< Resource busy */

/**
 * @brief Null pointer.
 */
#define MR_NULL                         ((void *)0)

/**
 * @brief Disable/enable.
 */
#define MR_DISABLE                      (0)                         /**< Disable */
#define MR_ENABLE                       (1)                         /**< Enable */

/**
 * @brief True/false.
 */
#define MR_FALSE                        (0)                         /**< False */
#define MR_TRUE                         (1)                         /**< True */

/**
* @brief Etask start flag.
*/
#define MR_ETASK_SFLAG_EVENT            (0x00)                      /* Event */
#define MR_ETASK_SFLAG_TIMER            (0x01)                      /* Timer */

/**
 * @brief Etask timer flag.
 */
#define MR_ETASK_SFLAG_HARD             (0x02)                      /* Hard */
#define MR_ETASK_SFLAG_SOFT             (0x00)                      /* Soft */
#define MR_ETASK_SFLAG_ONESHOT          (0x04)                      /* One shot */
#define MR_ETASK_SFLAG_PERIODIC         (0x00)                      /* Periodic */

/**
 * @brief Etask wakeup flag.
 */
#define MR_ETASK_WFLAG_NOW              (0x00)                      /* Wakeup immediately */
#define MR_ETASK_WFLAG_DELAY            (0x01)                      /* Wakeup after delay */
#define MR_ETASK_WFLAG_STATE            (0x02)                      /* Wakeup by state */

/**
 * @addtogroup Etask
 * @{
 */
void mr_etask_init(void *pool, size_t size);
void mr_etask_uninit(void);
void mr_etask_tick_update(void);
void mr_etask_handle(void);
int mr_etask_start(uint32_t id, uint8_t sflags, size_t time, int (*cb)(void *args), void *args);
int mr_etask_stop(uint32_t id);
int mr_etask_wakeup(uint32_t id, uint8_t wflag);
/** @} */
#endif /* MR_USING_ETASK */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _ETASK_H_ */
